# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=nghttp2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.46.0
pkgrel=1
pkgdesc="Framing layer of HTTP/2 is implemented as a reusable C library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://nghttp2.org/'
depends=("${MINGW_PACKAGE_PREFIX}-jansson"
         "${MINGW_PACKAGE_PREFIX}-jemalloc"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-c-ares")
checkdepends=("${MINGW_PACKAGE_PREFIX}-cunit")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
license=('MIT')
source=("https://github.com/nghttp2/nghttp2/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz")
sha256sums=('1a68cc4a5732afb735baf50aaac3cb3a6771e49f744bd5db6c49ab5042f12a43')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
}

build() {
  # Note, cmake system does not yet work well with this.
  [[ -d "${srcdir}/build-shared-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-shared-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-shared-${MINGW_CHOST}" && cd "${srcdir}/build-shared-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-hpack-tools \
    --enable-shared \
    --disable-static \
    --disable-examples \
    --disable-python-bindings

  make

  [[ -d "${srcdir}/build-static-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-static-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-static-${MINGW_CHOST}" && cd "${srcdir}/build-static-${MINGW_CHOST}"

  export CPPFLAGS="$CPPFLAGS -DLIBXML_STATIC -DNGHTTP2_STATICLIB"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-lib-only \
    --enable-static \
    --disable-shared

  make
}

#check() {
#  cd "${srcdir}"/build-${CARCH}
#  make check
#}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
